package cn.bearspark.idgenerator.provider.rpc;

import cn.bearspark.idgenerator.enumeration.IdCodeEnum;
import cn.bearspark.idgenerator.provider.service.IdGeneratorService;
import cn.bearspark.idgenerator.rpc.CommentIdGeneratorRpc;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.stereotype.Component;

/**
 * @author f
 */
@Component
@DubboService
public class CommentIdGeneratorRpcImpl implements CommentIdGeneratorRpc {

    private final IdGeneratorService idGeneratorService;

    public CommentIdGeneratorRpcImpl(IdGeneratorService idGeneratorService) {
        this.idGeneratorService = idGeneratorService;
    }

    @Override
    public Long genBldgId() {
        Long id = idGeneratorService.generateId(IdCodeEnum.COMMENT_ID);
        if (id == null) {
            return null;
        }
        return id * 2 + 1;
    }

    @Override
    public Long genLayerId() {
        Long id = idGeneratorService.generateId(IdCodeEnum.COMMENT_ID);
        if (id == null) {
            return null;
        }
        return id * 2;
    }
}
